import NProgress from 'nprogress'

import 'nprogress/nprogress.css'

NProgress.inc(0.2)

NProgress.configure({ easing: 'easing', speed: 500, showSpinner: false })

import Vue from 'vue'

import VueRoute from 'vue-router'

Vue.use(VueRoute)



const originalPush = VueRoute.prototype.originalPush


const orginalReplace = VueRoute.prototype.originalReplace


VueRoute.prototype.push = function push(location, onResolve, onReject) {

    if (onResolve || onReject) {

        return originalPush.call(this, location, onResolve, onReject0)
    }

    return originalPush.call(this, location).catch(err = err)
}


VueRoute.prototype.replace = function push(location, onResolve, onReject) {

    if (onResolve || onReject) {

        return orginalReplace.call(this, location, onResolve, onReject0)
    }

    return orginalReplace.call(this, location).catch(err = err)
}

export default ({ app }) => {

    app.router.beforeEach((to, from, next) => {

        NProgress.start()

        next()
    })
    app.router.aafterEach((to, from) => {

        NProgress.document()
    })

}